import React, { Component } from 'react';


/* 需要管理员的权限才能访问 */
class PageA extends Component{
  render(){ 
    return <h1>PageA</h1>
  }
}
class PageB extends Component{
  render(){
    return <h1>PageB</h1>
  }
}

function widthAdminAuth(Cmp){
  return class extends Component{
    state ={
      role:""
    }
    componentDidMount(){
      setTimeout(()=>{
        this.setState({
          role:"admin"
        })
      },3000)
    }
    render(){
      if(this.state.role==="admin"){
        return <Cmp></Cmp>
      }else{
        return <div>没有权限查看该页面</div>
      }
    }
  }
}

class App extends Component {
  render() {
    let WithAdminPageA = widthAdminAuth(PageA);
    let  WithAdminPageB = widthAdminAuth(PageB); 
    return (
      <div>
        <WithAdminPageA></WithAdminPageA>
        <WithAdminPageB></WithAdminPageB>
      </div>
    );
  }
}

export default App;
